package com.uuah.server.endpoint;

import java.net.URI;
import java.util.Properties;

import com.uuah.server.exception.endpoint.MalformedEndpointException;
import com.uuah.utils.StringUtils;

/**
 * <code>UrlEndpointBuilder</code> is the default endpointUri strategy suitable
 * for most connectors
 *
 * <p>
 * update record:updator，update time，update content and version
 * </p>
 *
 * @author <a href="jonny_quan@hotmail.com">jonny</a>
 * @date 2009 2009-3-27 下午01:38:31
 * @version 1.0.0
 */
public class UrlEndpointURIBuilder extends AbstractEndpointURIBuilder {

	protected void setEndpoint(URI uri, Properties props)
			throws MalformedEndpointException {
		address = "";
		if (uri.getHost() != null) {
			// set the endpointUri to be a proper url if host and port are set
			this.address = uri.getScheme() + "://" + uri.getHost();
			if (uri.getPort() != -1) {
				address += ":" + uri.getPort();
			}
		}
		if (StringUtils.isNotBlank(uri.getPath())) {
			address += uri.getPath();
		}

		if (StringUtils.isNotBlank(uri.getQuery())) {
			address += "?" + uri.getQuery();
		}
	}
}
